using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MapTestFramework.Common.Tests.Transforms;
using System.IO;

namespace MapTestFramework.Common.Tests
{
    [TestClass]
    public class TransformBaseMapExecuterFixture
    {
        #region Constructor And Initializing Members

        public TransformBaseMapExecuterFixture()
        {
            return;
        }

        #endregion

        #region Additional test attributes

        // [ClassInitialize()]
        // public static void ClassInitialize(TestContext testContext) { }
        // [ClassCleanup()]
        // public static void ClassCleanup() { }
        [TestInitialize()]
        public void TestInitialize() 
        {
            if (File.Exists(m_TargetPath))
                File.Delete(m_TargetPath);
            return;
        }
        // [TestCleanup()]
        // public void TestCleanup() { }

        #endregion

        #region Test Members

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ConstructMapNull()
        {
            try
            {
                TransformBaseMapExecuter executer =
                    new TransformBaseMapExecuter(null);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("map", ex.ParamName, "Invalid parameter name");
                Assert.AreEqual("Value cannot be null.\r\nParameter name: map", ex.Message, "Invalid error message");
                throw ex;
            }
        }
        [TestMethod]
        public void ExecuteMapValid()
        {
            TestableMapBaseMapExecuter executer = new TestableMapBaseMapExecuter(
                new Schema1_To_Schema2()
                );
            executer.ExecuteMap(m_SourcePath, m_TargetPath);
            Assert.IsTrue(File.Exists(m_TargetPath), "Target file does not exist");
            return;
        }
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ExecuteMapSourcePathEmpty()
        {
            try
            {
                TransformBaseMapExecuter executer = new TransformBaseMapExecuter(
                    new Schema1_To_Schema2()
                    );
                executer.ExecuteMap(string.Empty, m_TargetPath);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual(
                    "sourcePath", ex.ParamName, "Invalid parameter name."
                    );
                Assert.AreEqual(
                    "Value cannot be null or empty.\r\nParameter name: sourcePath",
                    ex.Message, "Invalid exception message."
                    );
                throw;
            }
            return;
        }
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ExecuteMapSourcePathNull()
        {
            try
            {
                TransformBaseMapExecuter executer = new TransformBaseMapExecuter(
                    new Schema1_To_Schema2()
                    );
                executer.ExecuteMap(null, m_TargetPath);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual(
                    "sourcePath", ex.ParamName, "Invalid parameter name."
                    );
                Assert.AreEqual(
                    "Value cannot be null or empty.\r\nParameter name: sourcePath",
                    ex.Message, "Invalid exception message."
                    );
                throw;
            }
            return;
        }
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ExecuteMapTargetPathEmpty()
        {
            try
            {
                TransformBaseMapExecuter executer = new TransformBaseMapExecuter(
                    new Schema1_To_Schema2()
                    );
                executer.ExecuteMap(m_SourcePath, string.Empty);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual(
                    "targetPath", ex.ParamName, "Invalid parameter name."
                    );
                Assert.AreEqual(
                    "Value cannot be null or empty.\r\nParameter name: targetPath",
                    ex.Message, "Invalid exception message."
                    );
                throw;
            }
            return;
        }
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ExecuteMapTargetPathNull()
        {
            try
            {
                TransformBaseMapExecuter executer = new TransformBaseMapExecuter(
                    new Schema1_To_Schema2()
                    );
                executer.ExecuteMap(m_SourcePath, null);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual(
                    "targetPath", ex.ParamName, "Invalid parameter name."
                    );
                Assert.AreEqual(
                    "Value cannot be null or empty.\r\nParameter name: targetPath",
                    ex.Message, "Invalid exception message."
                    );
                throw;
            }
            return;
        }

        #endregion

        #region Helper Members

        private const string m_SourcePath = "Schema1.xml";
        private const string m_TargetPath = "Schema2ExecuteMapValid.xml";

        #endregion
    }
}
